package com.shelpe.services.sinbadgateway.client;

import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.sinbadgateway.client.SimbaProxyClient.SimbaProxyClientFallback;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@FeignClient(name="${feign.simba.name}", url="${feign.simba.url}", fallback = SimbaProxyClientFallback.class)
public interface SimbaProxyClient {
	
	@RequestMapping(path = "/simba/taobao.simba.insight.catsdata.get", method = RequestMethod.GET,  consumes="application/json;charset=UTF-8")
	CategoryDataResponse findCategoryData(@RequestParam("category_id_list") String[] categoryIDs, @RequestParam("start_date")String startDate, 
			@RequestParam("end_date")String endDate, @RequestHeader("tenantID") long tenantID);
	
	@Data
	public static class CategoryDataResponse extends SimbaErrorResponse{
		
		@JsonProperty("simba_insight_catsdata_get_response")
		private CategoryDataRes res;
	}
	
	@Data
	public static class CategoryDataRes{
		@JsonProperty("cat_data_list")
		private CategoryWordDatas datas;
	}
	
	@Data
	public static class CategoryWordDatas{
		@JsonProperty("insight_category_data_d_t_o")
		private List<InsightWordData> wordDatas;
	}
	
	@Data
	public static class InsightWordData {
		
		public final static int NETWORK_PC_INTERNAL = 1;
		public final static int NETWORK_PC_EXTERNAL = 2;
		public final static int NETWORK_MOBILE_INTERNAL = 3;
		public final static int NETWORK_MOBILE_EXTERNAL = 4;

		private int impression;//展现量
		private int click;//点击量
		private int cost;//花费（分）
		@JsonProperty("directtransaction")
		private int directTransaction;//直接成交金额
		@JsonProperty("indirecttransaction")
		private int indirectTransaction;//间接成交金额
		@JsonProperty("directtransactionshipping")
		private int directTransactionShipping;//直接成交笔数
		@JsonProperty("indirecttransactionshipping")
		private int indirectTransactionShipping;//间接成交笔数
		@JsonProperty("favitemtotal")
		private int favItemTotal;//宝贝收藏数
		@JsonProperty("favshoptotal")
		private int favShopTotal;//店铺收藏数
		@JsonProperty("favtotal")
		private int favTotal;//总收藏数
		@JsonProperty("transactionshippingtotal")
		private int transactionShippingTotal;//总成交笔数
		@JsonProperty("transactiontotal")
		private int transactionTotal;//总成交金额
		private int competition;//竞争度
		private String ctr;//点击率
		private String cpc;//平均点击花费
		private String roi;//投入产出比
		private String coverage;//点击转化率
		
		private String bidword;//关键词
		@JsonProperty("cat_id")
		private String categoryID;
		@JsonProperty("cat_name")
		private String categoryName;
		private int network = -1;//流量来源：1:PC站内，2：PC站外,4:无线站内 5：无线站外
		private int mechanism = -1;//投放机制:0:关键词推广 2：定向推广 3：通用定向
		
	}
	
	@Service
	@Slf4j
	public static class SimbaProxyClientFallback implements SimbaProxyClient{

		@Override
		public CategoryDataResponse findCategoryData(String[] categoryIDs, String startDate, String endDate,
				long tenantID) {
			log.error("fallback findCategoryData: {}", categoryIDs != null?categoryIDs:"null");
			return new CategoryDataResponse();
		}
		
	}

}
